<?php
/**
 * Institution 封装来自 institution 数据表的记录及领域逻辑
 * @author Administrator
 *
 */
namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Identify extends Model
{
	protected $table = 'identify';
	
	protected $fillable = array('uid', 'code','mobile','type');
	
	protected function getDateFormat()
	{
		return date(time());
	}
	/*
	 * 验证 验证码
	 * time  多久失效(默认半个小时)
	 */
	protected function checkIdentify($phone,$type,$code,$time=1800){
		$identify=Identify::where('code',$code)->where('mobile',$phone)->where('type',$type)->first();
		if(isset($identify->id) && $identify->id){
			$created_at = $identify->created_at;
			if((time()-strtotime($created_at)) > $time){
				//过期
				return -1;
			}else{
				//正确
				return 1;
			}
		}else{
			//错误
			return 0;
		}
	}
}
